package com.ruoyi.project.g6.api;

import com.ruoyi.project.g6.entity.*;
import com.ruoyi.project.g6.entity.common.FileEntity;
import com.ruoyi.project.g6.entity.common.ResponseResult;
import com.ruoyi.project.g6.entity.vo.*;
import com.ruoyi.project.g6.tools.SetDefaultValueBean;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import sun.misc.BASE64Encoder;

import java.io.FileInputStream;

public class ApiDeploy {

    public static final String token = "08cff531227a45c2bb490c2db9230121_feidie";


    public static void main(String[] args) {
        Api api = new Api();
        login(api);
        //insertVehicleEngine(api);
        //getChipModel(api);
        // 2019年12月11日 15:49:10 显示已备案
        //insertChipModel(api);
        //getTboxModel(api);
        //insertTbox(api);
        //insertVehicle(api);
        //insertVehicle(api);
        //vehicleStatus(api);
        //FileEntity fileEntity = getFileEntity("E:\\2345下载\\2665fe1fbe096b636b77085f03338744ebf8ac72.jpg");
        //System.out.println(fileEntity);
        // insertVehicleEngine(api); //操作成功 2019年12月12日 09:16:54
        //insertVehicleType(api);
        //getChipPrefix(api);
        //getChipPrefixResult(api);
        //insertTboxModelAuthority(api);
        getChipPrefixResult(api);
        insertTboxModelAuthorityResult(api);
    }


    //-----------------------------车辆型号模块-------------------------------------------------------//
    // 型号备案一定要在发动机,芯片,终端备案之后
    private static void insertVehicleType(Api api) {
        VehicleTypeVO vehicleTypeVO = new VehicleTypeVO();
        vehicleTypeVO.setToken(token);

        VehicleType vehicleType = new VehicleType();
        vehicleType.setModelCn("FD3047W17K5-1");
        vehicleType.setEngineType("WP2.3Q110E50");
        vehicleType.setEngineEmissionLevel("国五");
        vehicleType.setVehicleFirm("浙江飞碟汽车制造有限公司");
        vehicleType.setFactoryModel("飞碟");

        vehicleType.setChassisModel("FD3047W17K5");
        vehicleType.setChassisFirm("浙江飞碟汽车制造有限公司");
        vehicleType.setMaxSpeed(85);
        vehicleType.setAxlesNumber("2");
        vehicleType.setWheelBase1(2860D);
        vehicleType.setWheelBase2("1590/1570");
        vehicleType.setTireNumber(6);
        vehicleType.setTireSpec("7.50R16LT 6PR");
        vehicleType.setDriveType("4*2 第2轴");
        vehicleTypeVO.setStrVehicleModel(vehicleType);

        ResponseResult responseResult = api.insertVehicleType(vehicleTypeVO);
        System.out.println(responseResult);
    }


    //-----------------------------发动机模块-------------------------------------------------------//

    private static void insertVehicleEngine(Api api) {
        VehicleEngineVO vehicleEngineVO = new VehicleEngineVO();
        vehicleEngineVO.setToken(token);

        VehicleEngine vehicleEngine = new VehicleEngine();
        vehicleEngine.setEngineModel("WP2.3Q110E50");
        //vehicleEngine.setEngineModel("TEST.wz201912170945");
        vehicleEngine.setEngineFirmId("913700007456765902");
        vehicleEngine.setEngineFirmName("潍柴动力股份有限公司");
        vehicleEngine.setEngineType("柴油机");
        vehicleEngine.setEmissionLevel("2");

//
//
//        vehicleEngine.setEpaPublicInfoNum("CN CJ G5 00 0284000001 000001");
//        vehicleEngine.setEngineSweptVolume("2.29");
//        vehicleEngine.setEngineCylinderArrangement("直列");
//        vehicleEngine.setEngineMaxPowerSpeed("81/3200");
//        vehicleEngine.setEngineMaxTorqueSpeed("280/1600-2400");
//        vehicleEngine.setPcdExhaustType(1);
//        vehicleEngine.setEtcCycleWork("11.5");
//        vehicleEngine.setWthcCycleWork("/");
//
//        vehicleEngine.setEngineRatedPower("81");
//        vehicleEngine.setEngineArrangement("纵置");
//        vehicleEngine.setEngineAuxiliaryEmission("/");
//        vehicleEngine.setEngineAuxiliaryFirm("/");
//        vehicleEngine.setEngineCombustionChamber("ω");
//        vehicleEngine.setEngineCompressionRatio("17.5:1");
//        vehicleEngine.setEngineCoolingMethod("液冷");
//        vehicleEngine.setEngineCylinderBoreStroke("4-89×92");
//        vehicleEngine.setEngineCylinderPitch(100);
//        vehicleEngine.setEngineCylinderStructure("五缸套");
//        vehicleEngine.setEngineECUHardwareFirm("博世汽车柴油系统有限公司");
//        vehicleEngine.setEngineECUHardwareModel("WPEDC7");
//        vehicleEngine.setEngineECUSoftwareFirm("博世汽车柴油系统有限公司");
//        vehicleEngine.setEngineECUSoftwareModel("50211032");
//        vehicleEngine.setEngineEGRFirm("/");
//        vehicleEngine.setEngineEGRModel("/");
//        vehicleEngine.setEngineExhaustBackPressure(20);
//        vehicleEngine.setEngineFuelSulfur("柴油，10");
//        vehicleEngine.setEngineFuelSupplyForm("高压共轨");
//        vehicleEngine.setEngineGovernorFirm("/");
//        vehicleEngine.setEngineGovernorModel("/");
//        vehicleEngine.setEngineIdleSpeed(750);
//        vehicleEngine.setEngineIgnitionMode("压燃");
//        vehicleEngine.setEngineInjectionFirm("博世汽车柴油系统有限公司");
//        vehicleEngine.setEngineInjectionModel("CRI40-Y");
//        vehicleEngine.setEngineInjectionPumpFirm("博世汽车柴油系统有限公司");
//        vehicleEngine.setEngineInjectionPumpModel("CRP40-Y");
//        vehicleEngine.setEngineInjectorPressure(160);
//        vehicleEngine.setEngineInletMode("增压中冷");
//        vehicleEngine.setEngineIntakeResistance(6);
//
//        vehicleEngine.setEngineIntercoolerOutTem("50");
//        vehicleEngine.setEngineMaxEmptySpeed(3520);
//        vehicleEngine.setMaximumNetPower("77/3200");
//        vehicleEngine.setEngineRatedFuelSupply("0.0605");
//        vehicleEngine.setEngineSingleValveNum("1/1");
//        vehicleEngine.setEngineStrokeFuelSupply("0.0626");
//        vehicleEngine.setEngineTurboChargerFirm("康跃科技股份有限公司");
//        vehicleEngine.setEngineTurboChargerModel("JP45K");
//        vehicleEngine.setPcdParticulateModel("/");
//        vehicleEngine.setPcdParticulatePosition("/");
//        vehicleEngine.setPcdParticulateStructure("/");
//        vehicleEngine.setPcdParticulateType("/");
//        vehicleEngine.setPcdParticulateVolume("/");
//        vehicleEngine.setPcdPostProcessingFirm("潍柴动力股份有限公司");
//        vehicleEngine.setPcdPostProcessingModel("WPSM-001");
//        vehicleEngine.setPcdReactantTemperature("266-343");
//        vehicleEngine.setPcdReactantType("尿素水液，32.5%");
//        vehicleEngine.setPcdRegenerationTemperature("/");
//        vehicleEngine.setPcdRegeneration("/");
//
//        vehicleEngine.setPcdAirInjectionType("/");
//        vehicleEngine.setPcdCarrierDensity("300目");
//        vehicleEngine.setPcdCarrierFirm("山东奥褔环保科技股份有限公司");
//        vehicleEngine.setPcdCarrierMaterial("蜂窝状堇青石");
//        vehicleEngine.setPcdCatalyticFirm("潍柴动力空气净化科技有限公司");
//        vehicleEngine.setPcdCatalyticFormMaterial("堇青石");
//        vehicleEngine.setPcdCatalyticForm("选择性催化还原");
//        vehicleEngine.setPcdCatalyticModel("WPSCR-002");
//        vehicleEngine.setPcdCatalyticNum("1");
//        vehicleEngine.setPcdCatalyticTemperature("423-823");
//        vehicleEngine.setPcdCatalyticType("/");
//        vehicleEngine.setPcdCatalyticUnitsNum("2");
//        vehicleEngine.setPcdCatalyticVolume(20399);
//        vehicleEngine.setPcdETCCyclesNum("/");
//
//        vehicleEngine.setPcdMufflerFirm("潍柴动力空气净化科技有限公司");
//        vehicleEngine.setPcdMufflerModel("WPSCR-002");
//        vehicleEngine.setPcdNoSensorFirm("潍柴动力空气净化科技有限公司");
//        vehicleEngine.setPcdNoSensorType("UNINOx Sensor");
//        vehicleEngine.setPcdPaintCoatFirm("庄信万丰(上海)化工有限公司");
//        vehicleEngine.setPcdParticulateFirm("/");
//        vehicleEngine.setPcdParticulateMethod("/");
//
//        vehicleEngine.setTestCycleWork("11.5");

        vehicleEngineVO.setStrEngine(vehicleEngine);
        ResponseResult responseResult = api.insertVehicleEngine(vehicleEngineVO);
        System.out.println(responseResult);
    }


    //-----------------------------车辆信息模块-------------------------------------------------------//
    private static void vehicleStatus(Api api) {
        GetVehicleStatusVO getVehicleStatusVO = new GetVehicleStatusVO();
        getVehicleStatusVO.setToken(token);
        getVehicleStatusVO.setType("1");
        getVehicleStatusVO.setVin("LZ0B9JB25K1190143");
        ResponseResult responseResult = api.vehicleStatus(getVehicleStatusVO);
        System.out.println(responseResult);
    }

    private static void insertVehicle(Api api) {
        VehicleVO vehicleVO = new VehicleVO();
        vehicleVO.setToken(token);
        Vehicle vehicle = new Vehicle();

        vehicle.setVehicleLoad("2500");
        vehicle.setGrossVehicleMass("4495");
        //vehicle.setVehicleModel("FD3047W17K5-1");
        vehicle.setVehicleFrameNo("LZ0B9JB36K1024979");
        //vehicle.setEngineModel("WP2.3Q110E50");
       // vehicle.setEngineNo("BE05216749");
        vehicle.setChipType("FM1280");
        vehicle.setTboxType("SVT81");
        vehicle.setVehRegisterMode("0");
        vehicle.setEmissionLevelType("2");
        vehicle.setVehicleFirm("浙江飞碟汽车制造有限公司");

        SetDefaultValueBean.setDefaultValue(vehicle);
        vehicleVO.setStrVehicle(vehicle);
        ResponseResult responseResult = api.insertVehicle(vehicleVO);
        System.out.println(responseResult);
    }


//-----------------------------终端模块-------------------------------------------------------//

    private static void getTboxModel(Api api) {
        GetTboxModelVo getTboxModelVo = new GetTboxModelVo();
        getTboxModelVo.setToken(token);
        ResponseResult tboxModel = api.getTboxModel(getTboxModelVo);
        System.out.println(tboxModel);
    }
    private static void insertTboxModelAuthorityResult(Api api) {
        CommonVo commonVo =new CommonVo();
        commonVo.setRequestID("362e5160d9bc448b935c0276445be6c1");
        commonVo.setToken(token);
        ResponseResult responseResult = api.insertTboxModelAuthorityResult(commonVo);
        System.out.println(responseResult);
    }
    private static void insertTboxModelAuthority(Api api) {
        TboxModelAuthority tboxModelAuthority = new TboxModelAuthority();
        tboxModelAuthority.setToken(token);

        tboxModelAuthority.setTboxModelName("SVT81");
        tboxModelAuthority.setContactorName("郑辉");
        tboxModelAuthority.setContactorPhone("13621731795");
        tboxModelAuthority.setAuthorizeFile(getFileEntity("E:\\五征重要文件\\附件\\svt81.jpg"));

        ResponseResult responseResult = api.insertTboxModelAuthority(tboxModelAuthority);
        System.out.println(responseResult);
    }
    /**
     * 2019年12月11日 16:12:46
     *
     * @param api
     */
    private static void insertTbox(Api api) {
        TboxVO tbox = new TboxVO();
        tbox.setToken(token);

        Tbox tbox1 = new Tbox();
        tbox1.setTboxModel("SVT81");
        tbox1.setTboxFactoryId("913101183422290164");
        tbox1.setTboxFactoryName("上海势航网络科技有限公司");
        tbox1.setContactorName("郑辉");
        tbox1.setContactorPhone("13621731795");
        tbox1.setTboxFactoryNote("以北斗和车联网技术为依托,服务于整车、金融保险和物流运输行业的大数据平台公司。");
        tbox1.setTboxFactoryLicenceImg(getFileEntity("E:\\五征重要文件\\附件\\终端-上海势航网络科技有限公司营业执照(三证合一).jpg"));

        tbox.setStrTbox(tbox1);
        ResponseResult responseResult = api.insertTbox(tbox);
        System.out.println(responseResult);
    }


//-----------------------------芯片模块-------------------------------------------------------//

    private static void getChipPrefix(Api api) {
        ChipPrefix chipPrefix= new ChipPrefix();
        chipPrefix.setChipModelName("FM1280");
        chipPrefix.setContactorName("程宇");
        chipPrefix.setContactorPhone("18221585801");
        chipPrefix.setAuthorizeFile(getFileEntity("E:\\五征重要文件\\附件\\xp.jpg"));
        ResponseResult responseResult = api.getChipPrefix(chipPrefix,token);
        System.out.println(responseResult);
    }

    private static void getChipPrefixResult(Api api) {
       //f4853b187ff64432905242b062ef6123
        CommonVo commonVo =new CommonVo();
        commonVo.setRequestID("f4853b187ff64432905242b062ef6123");
        commonVo.setToken(token);
        ResponseResult responseResult = api.getChipPrefixResult(commonVo);
        System.out.println(responseResult);
    }
    /**
     * 插入芯片备案
     * 2019年12月11日 15:53:05 显示已备案 ???
     *
     * @param api
     */
    private static void insertChipModel(Api api) {
        ChipModelVO chipModelVO = new ChipModelVO();
        chipModelVO.setToken(token);

        ChipModel chipModel = new ChipModel();
        chipModel.setChipModel("TEST2019");
        chipModel.setChipFactoryId("测试公司");
        chipModel.setChipFactoryName("测试公司");
        chipModel.setContactorName("测试");
        chipModel.setContactorPhone("13322332233");
        chipModel.setChipFactoryNote("hhhh");
//        chipModel.setChipModel("FM1280");
//        chipModel.setChipFactoryId("91310000631137409");
//        chipModel.setChipFactoryName("上海复旦微电子集团股份有限公司");
//        chipModel.setContactorName("程宇");
//        chipModel.setContactorPhone("18221585801");
//        chipModel.setChipFactoryNote("上海复旦微电子集团股份有限公司，是一家从事超\n" +
//                "大规模集成电路的设计、开发、测试，并为客户提\n" +
//                "供系统解决方案的专业公司。");

        chipModel.setChipFactorylicence(getFileEntity("E:\\五征重要文件\\附件\\芯片-营业执照.jpg"));
        chipModel.setIso9001Img(getFileEntity("E:\\五征重要文件\\附件\\芯片-ISO9001.pdf"));
        chipModel.setIos14001_img(getFileEntity("E:\\五征重要文件\\附件\\芯片-ISO14001.pdf"));
        chipModel.setGuomiImg(getFileEntity("E:\\五征重要文件\\附件\\芯片-国密资质文件-二级证书.jpg"));

        chipModelVO.setStrChip(chipModel);
        ResponseResult responseResult = api.insertChipModel(chipModelVO);
        System.out.println(responseResult);
    }

    private static void getChipModel(Api api) {
        GetChipModelVo chipModelVO = new GetChipModelVo();
        chipModelVO.setToken(token);
        chipModelVO.setChipModel("");
        ResponseResult chipModel = api.getChipModel(chipModelVO);
        System.out.println(chipModel);
    }


    private static void login(Api api) {
        Auth auth = new Auth();
        auth.setUsername("feidie");
        auth.setPassword("wz666666_");
        ResponseResult login = api.login(auth);
        System.out.println(login);
    }


    private static FileEntity getFileEntity(String filePath) {
        try {
            FileInputStream fileInputStream = new FileInputStream(filePath);
            byte[] bytes = IOUtils.toByteArray(fileInputStream);
            String encode = new BASE64Encoder().encode(bytes);
            FileEntity fileEntity = new FileEntity();
            fileEntity.setValue(encode);
            fileEntity.setFileName(FilenameUtils.getBaseName(filePath));
            fileEntity.setType(FilenameUtils.getExtension(filePath));
            return fileEntity;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("文件转换错误");
        }
    }
}
